package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseAttrInfo;
import com.atguigu.gmall.product.entity.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseAttrValueService;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class AttrController {
    @Autowired
    BaseAttrInfoService baseAttrInfoService;
    @Autowired
    BaseAttrValueService baseAttrValueService;
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") long attrId){
        List<BaseAttrValue> list = baseAttrValueService.getAttrValueList(attrId);


        return Result.ok(list);
    }

    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){


        baseAttrInfoService.saveAttrInfo(baseAttrInfo);

        return Result.ok();
    }
    //查询分类下平台属性
    @GetMapping("/attrInfoList/{c1id}/{c2id}/{c3id}")
    public Result attrInfoList(@PathVariable("c1id")long c1id,@PathVariable("c2id")long c2id,@PathVariable("c3id")long c3id){
        List<BaseAttrInfo> result = baseAttrInfoService.getAttrsAndValueByCategory(c1id,c2id,c3id);

        return Result.ok(result);
    }
}
